﻿using ShareCode.Dto;
using ShareCode.Dto.User.Org.Admin;
using ShareCode.Entity.User;
using ShareCode.KeyValue;

namespace ClientDao.User
{
    public class UserOrgDal : BaseTreeDal<UserOrgEntity>
    {
        public UserOrgDal()
        {
            Controller += "User/UserOrg";
        }

        public async Task<ResultDto<long>> AdminNew(NewOrgDto entity, string? IcoUrlPath)
        {
            var val = InitDataContent(entity);

            if (!string.IsNullOrEmpty(IcoUrlPath))
                val = InitFileDataContent(val, IcoUrlPath, EnumFileUsage.OrgIcon.ToString());

            var imgstream = await PostFormAsync<long>($"AdminNew", val);

            return imgstream;
        }

        public async Task<ResultDto<PagingWithDataModel<AdminListDto>>> AdminList(PagingDto dto)
        {
            return await PostAsync<PagingDto, PagingWithDataModel<AdminListDto>>($"AdminList", dto);
        }

        public async Task<ResultDto<long>> Update(UserOrgEntity entity, string IcoUrlPath)
        {
            var val = InitDataContent(entity);
            if (!string.IsNullOrEmpty(IcoUrlPath))
                val = InitFileDataContent(val, IcoUrlPath, EnumFileUsage.OrgIcon.ToString());

            var imgstream = await PostFormAsync<long>($"Update", val);

            return imgstream;
        }
    }
}
